package command;

import indexingSystem.Document;
import indexingSystem.IndexingSystem;

import java.io.File;
import java.util.Vector;

public class ReadDocument implements Command{
	
	public void execute(Vector<String> args) throws Exception {
		if (args == null)
			throw new Exception(getCommandUsage());
		if (args.size() > 1)
			throw new Exception(getCommandUsage());
		File file = new File(args.get(0));
		if(!file.exists())
			throw new Exception("File not found: "+file.getAbsolutePath());
		if (!file.canRead())
			throw new Exception("Cannot read: "+file.getAbsolutePath());
		IndexingSystem.addDocument(new Document(file.getAbsolutePath()));
	}
	public String getCommandName(){
		return "readdocument";
	}
	public boolean commandHasArgs() {
		return true;
	}
	public String getCommandUsage() {
		return getCommandName()+" <file>";
	}
}
